<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace Yj\Constants;

use Hyperf\Utils\Str;
use ReflectionClassConstant;

class AnnotationReader
{
    public function getAnnotations(array $classConstants)
    {
        $result = [];
        /** @var ReflectionClassConstant $classConstant */

        foreach ($classConstants as $classConstant) {

            $code = $classConstant->getValue();


            $attributes = $classConstant->getAttributes();


            // Not support float and bool, because it will be convert to int.
            if ($attributes && (is_int($code) || is_string($code))) {
                $result[$code] = $this->parseAttributes($attributes);
            }

        }
        return $result;
    }

    private function parseAttributes(array $attributes)
    {
        $data = [];
        /** @var \ReflectionAttribute $attribute */
        foreach ($attributes as  $attribute){
            $data[($attribute->getName())] = $attribute->getArguments()[0]??'';
        }
        return $data;
    }




}
